package edu.westga.vocalengineer.audio.transforms;

/**
 * Applies a pitch change (i.e. changes the pitch of sound without changing
 * the duration)
 * @author mfarmer2
 *
 */
public class PitchChangeTransform implements ITransform {

	protected float pitchChangeAmount;
	
	/**
	 * Sets up the pitch change.
	 * @param amount The strength of the change as a ratio.
	 */
	public PitchChangeTransform(float amount) {
		pitchChangeAmount = amount;
	}
	
	/**
	 * Applies the pitch change to a byte buffer.
	 */
	@Override
	public short[] execute(short[] samples) {
		
		int lastSample = (int)((float)samples.length / pitchChangeAmount);
		short[] filtered = new short[lastSample];
		
		for(int i = 0; i < lastSample; i++) {
			filtered[i] = samples[(int)((float) i * pitchChangeAmount)];
		}
		
		return filtered;
	}

}
